import groovy.jmx.builder.JmxBuilder
import javax.management.MBeanServer
import javax.management.ObjectName

class JmxObjectNameFactoryTest extends GroovyTestCase {
    def jmx

    void testInitializtion() {
        jmx = new JmxBuilder()
        assertTrue jmx != null
    }

    void setUp() {
        jmx = new JmxBuilder()
    }

    void testJmxObjectNameFactoryExplicit() {
        def observed = new ExposedTestBean(id: "TestBean")
        MBeanServer parent = jmx.export {
            bean(observed) {
                name("jmxBuilder:type=bean")
                description("This is a test bean")
            }
        }

        assert parent
        assert parent.isRegistered(new ObjectName("jmxBuilder:type=bean"))
        assert parent.getMBeanInfo(new ObjectName("jmxBuilder:type=bean")).getDescriptor().getFieldValue("displayName") == "This is a test bean"

        parent.unregisterMBean new ObjectName("jmxBuilder:type=bean")
    }


}